﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace TestSocket
{
    /// <summary>
    /// Interaction logic for ConfigPanel.xaml
    /// </summary>
    public partial class ConfigPanel : UserControl, IPanel
    {
        MainWindow m_wnd;

        public ConfigPanel(MainWindow wnd)
        {
            InitializeComponent();
            m_wnd = wnd;
        }

        public void OnActivate()
        {
            if (m_wnd.bServerMode)
            {
                btnAction.Content = "Start Listening";                                
                tbIPAddrDest.IsEnabled = false;
            }
            else
            {
                btnAction.Content = "Connect..";                
            }
            tbIPAddrSrc.Text = "0.0.0.0";
            tbBinaryPort.Text = "6000";
            tbMsgPort.Text = "5000";            
        }

        public void OnDeactivate()
        {
            
        }

        public void OnAppClosing()
        {
            
        }

        private void btnAction_Click(object sender, RoutedEventArgs e)
        {
            m_wnd.strDestIP = tbIPAddrDest.Text;
            m_wnd.strSrcIP = tbIPAddrSrc.Text;
            m_wnd.strBinaryPort = tbBinaryPort.Text;
            m_wnd.strMsgPort = tbMsgPort.Text;
            if (m_wnd.bServerMode)
                m_wnd.nxtScrn = ePanel.pnlAcceptedSocket;
            else 
                m_wnd.nxtScrn = ePanel.pnlConnectedSockets;
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            Keyboard.Focus(tbIPAddrSrc);
        }
    }
}
